/*
 * @Description: 业绩页面
 * @Author: iamsmiling
 * @Date: 2021-06-10 21:15:11
 * @LastEditTime: 2021-06-14 17:43:44
 */
import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/components/button/roatet_button.dart';
import 'package:credit_business_circle/components/image/chimera_image.dart';
import 'package:credit_business_circle/domain/remote/kpi/kpi_record_entity.dart';
import 'package:credit_business_circle/pages/mine/children/partner/children/kpi/kpi_controller.dart';
import 'package:credit_business_circle/routes/app_routes.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class KpiPage extends GetView<KpiController> {
  const KpiPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: R.color.ffffffff,
      appBar: AppBar(
        title: Text("业绩总览"),
      ),
      body: CustomScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: Image.asset(
              R.image.kpiBanner,
              width: R.dimen.width,
              fit: BoxFit.fill,
            ),
          ),
          SliverToBoxAdapter(
            child: Container(
              margin: EdgeInsets.only(
                  left: R.dimen.dp13,
                  right: R.dimen.dp13,
                  top: R.dimen.dp14,
                  bottom: R.dimen.dp10),
              child: DefaultTextStyle(
                style:
                    TextStyle(color: R.color.fffcf2d5, fontSize: R.dimen.sp14),
                child: Stack(
                  alignment: Alignment.center,
                  children: [
                    Image.asset(
                      R.image.kpiBg,
                      width: R.dimen.width,
                      fit: BoxFit.cover,
                    ),
                    Container(
                      padding: EdgeInsets.only(
                          top: R.dimen.dp24,
                          left: R.dimen.dp20,
                          right: R.dimen.dp20,
                          bottom: R.dimen.dp18),
                      child: Column(
                        children: [
                          Row(
                            children: [
                              Text("可提现的星币："),
                              Spacer(),
                              GestureDetector(
                                onTap: () => Get.toNamed(
                                    Get.currentRoute + AppRoutes.kpiBill),
                                child: Row(
                                  children: [
                                    Image.asset(R.image.kpiBill),
                                    Container(
                                      margin:
                                          EdgeInsets.only(left: R.dimen.dp8),
                                      child: Text("星币明细"),
                                    )
                                  ],
                                ),
                              )
                            ],
                          ),
                          Container(
                            margin: EdgeInsets.only(
                                top: R.dimen.dp30, bottom: R.dimen.dp32),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Text.rich(TextSpan(
                                    text: "464",
                                    style: TextStyle(
                                        color: R.color.fffde9ae,
                                        fontSize: R.dimen.sp34,
                                        fontWeight: FontWeight.w600),
                                    children: [
                                      TextSpan(
                                        text: " 星币",
                                        style: TextStyle(
                                            fontSize: R.dimen.sp18,
                                            fontWeight: FontWeight.w600),
                                      )
                                    ])),
                                Spacer(),
                                GestureDetector(
                                  onTap: () => Get.toNamed(
                                      Get.currentRoute + AppRoutes.withdrawal),
                                  child: Row(
                                    children: [
                                      Container(
                                        margin: EdgeInsets.only(
                                            right: R.dimen.dp10),
                                        child: Text(
                                          "申请提现",
                                          style: TextStyle(
                                              color: R.color.ff222741,
                                              fontSize: R.dimen.sp13),
                                        ),
                                      ),
                                      Image.asset(
                                        R.image.next,
                                        color: R.color.ff333333,
                                      )
                                    ],
                                  ),
                                )
                              ],
                            ),
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [Text("待审核：500星币"), Text("已提现：1520星币")],
                          )
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
          SliverToBoxAdapter(
            child: Container(
              margin: EdgeInsets.only(
                left: R.dimen.dp12,
                right: R.dimen.dp12,
                bottom: R.dimen.dp18,
              ),
              child: Text(
                "注：邀请的会员充值后可获取星币奖励。星币兑换比例: 1星币=1元",
                style:
                    TextStyle(fontSize: R.dimen.sp12, color: R.color.ffd88a01),
              ),
            ),
          ),
          SliverToBoxAdapter(
            child: Container(
              margin: EdgeInsets.symmetric(horizontal: R.dimen.dp12),
              child: Column(
                children: [
                  Container(
                    margin: EdgeInsets.only(bottom: R.dimen.dp10),
                    child: Row(
                      children: [
                        Text(
                          "我的邀请",
                          style: TextStyle(
                              fontSize: R.dimen.sp15,
                              color: R.color.ff111111,
                              fontWeight: FontWeight.w600),
                        ),
                        Spacer(),
                        RotateButton(
                          onPressed: () => Future.value(0),
                          label: Container(
                            margin: EdgeInsets.only(right: R.dimen.dp10),
                            child: Text(
                              "收起",
                              style: TextStyle(
                                  fontSize: R.dimen.sp13,
                                  color: R.color.ff888888),
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.only(
                        left: R.dimen.dp24,
                        right: R.dimen.dp24,
                        top: R.dimen.dp24,
                        bottom: R.dimen.dp20),
                    decoration: BoxDecoration(
                        color: R.color.fff7f7f7,
                        borderRadius: BorderRadius.circular(R.dimen.sp5)),
                    child: Column(
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          children: [
                            Column(
                              children: [
                                Text(
                                  "0",
                                  style: TextStyle(
                                      fontWeight: FontWeight.w600,
                                      fontSize: R.dimen.sp25,
                                      color: R.color.fffe6407),
                                ),
                                Container(
                                  margin: EdgeInsets.only(top: R.dimen.dp15),
                                  child: Text(
                                    "今日邀请",
                                    style: TextStyle(
                                        fontSize: R.dimen.sp13,
                                        color: R.color.ff333333,
                                        fontWeight: FontWeight.w600),
                                  ),
                                ),
                              ],
                            ),
                            Container(
                              color: R.color.ffdddddd,
                              height: R.dimen.dp48,
                              width: .5,
                            ),
                            Column(
                              children: [
                                Text(
                                  "10",
                                  style: TextStyle(
                                      fontWeight: FontWeight.w600,
                                      fontSize: R.dimen.sp25,
                                      color: R.color.fffe6407),
                                ),
                                Container(
                                  margin: EdgeInsets.only(top: R.dimen.dp15),
                                  child: Text(
                                    "累计邀请",
                                    style: TextStyle(
                                        fontSize: R.dimen.sp13,
                                        color: R.color.ff333333,
                                        fontWeight: FontWeight.w600),
                                  ),
                                ),
                              ],
                            ),
                            Container(
                              color: R.color.ffdddddd,
                              height: R.dimen.dp48,
                              width: .5,
                            ),
                            Column(
                              children: [
                                Text(
                                  "6",
                                  style: TextStyle(
                                      fontWeight: FontWeight.w600,
                                      fontSize: R.dimen.sp25,
                                      color: R.color.fffe6407),
                                ),
                                Container(
                                  margin: EdgeInsets.only(top: R.dimen.dp15),
                                  child: Text(
                                    "有效邀请",
                                    style: TextStyle(
                                        fontSize: R.dimen.sp13,
                                        color: R.color.ff333333,
                                        fontWeight: FontWeight.w600),
                                  ),
                                ),
                              ],
                            ),
                          ],
                        ),
                        Container(
                          margin: EdgeInsets.only(top: R.dimen.dp28),
                          child: Text(
                            "注：该页面数据统计有一定的延迟。",
                            style: TextStyle(
                                fontSize: R.dimen.sp12,
                                color: R.color.ffbd7901),
                          ),
                        )
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
          SliverList(
              delegate:
                  SliverChildBuilderDelegate((BuildContext context, int i) {
            KpiRecordEntity record = controller.records[i];
            return Container(
              margin: EdgeInsets.only(
                  top: R.dimen.dp10, left: R.dimen.dp12, right: R.dimen.dp12),
              padding: EdgeInsets.only(
                  left: R.dimen.dp10,
                  right: R.dimen.dp16,
                  top: R.dimen.dp12,
                  bottom: R.dimen.dp12),
              decoration: BoxDecoration(
                  color: R.color.fff5f5f5,
                  borderRadius: BorderRadius.circular(R.dimen.sp5)),
              child: Row(
                children: [
                  Container(
                    margin: EdgeInsets.only(right: R.dimen.dp10),
                    child: ChimeraImage(
                      src: record.avatar,
                      width: R.dimen.dp40,
                      height: R.dimen.dp40,
                      borderRadius: BorderRadius.circular(R.dimen.dp40 / 2),
                    ),
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "${record.name}",
                        style: TextStyle(
                            fontSize: R.dimen.sp14,
                            color: R.color.ff111111,
                            fontWeight: FontWeight.w600),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: R.dimen.dp5),
                        child: Text(
                          "${record.telephone}",
                          style: TextStyle(
                              fontSize: R.dimen.sp13, color: R.color.ff555555),
                        ),
                      )
                    ],
                  ),
                  Spacer(),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "人数：${record.count}人",
                        style: TextStyle(
                            fontSize: R.dimen.sp14,
                            color: R.color.ff222222,
                            fontWeight: FontWeight.w600),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: R.dimen.dp5),
                        child: Text(
                          "${record.telephone}",
                          style: TextStyle(
                              fontSize: R.dimen.sp12, color: R.color.ff777777),
                        ),
                      )
                    ],
                  ),
                  Spacer(),
                  Text(
                    "${record.valid ? '有效' : '无效'}",
                    style: TextStyle(
                        fontSize: R.dimen.sp14,
                        fontWeight: FontWeight.w600,
                        color:
                            record.valid ? R.color.ff1fa37d : R.color.ff666666),
                  )
                ],
              ),
            );
          }, childCount: controller.records.length))
        ],
      ),
    );
  }
}
